package com.happy.study.servier.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happy.study.dao.FeedMapper;
import com.happy.study.entity.FeedEntity;
import com.happy.study.servier.IFeedService;
import com.happy.study.util.StateEnum;
import com.happy.study.util.StateException;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class FeedServiceImpl extends ServiceImpl<FeedMapper, FeedEntity> implements IFeedService {

    @Override
    public FeedEntity addSingle ( FeedEntity feedEntity ) {
        if ( feedEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        feedEntity.setCreateTime ( new Date () );
        int insert = baseMapper.insert ( feedEntity );
        if ( insert == 0 ) {
            throw new StateException ( StateEnum.INSERT_EXCE );
        }
        return feedEntity;
    }
}
